// pages/me/me.js
const app = getApp();
Component({
  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 1
        })
      }

      this.setData({
        userInfo: app.globalData.userInfo
      })

      this.updatePublic()
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userInfo: null,
    public: {
      title: null,
      time: '',
      content: ''
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /* 登陆事件
    loginAction: function () {
      let host = getApp().globalData.host
      let self = this;

      wx.getUserInfo({
        success(res) {
          getApp().globalData.userInfo = res.userInfo
          self.setData({
            userInfo: res.userInfo
          })
        }
      })

      wx.login({
        success: function (res) {
          if (res) {
            wx.request({
              url: host + '/user/login',
              data: {
                code: res.code
              },
              success: function (res) {
                // TODO 保存 token 到 storage, 获取用户信息并显示
                wx.setStorage({
                  key: 'token',
                  data: res.data.result,
                })
              }
            })

          } else {
            console.log(res.errMsg)
          }
        }
      }) 
    }*/
    targetTo: function (e) {
      let url = e.currentTarget.dataset.target
      wx.navigateTo({
        url: url,
      })
    },

    updatePublic: function () {
      let host = app.globalData.host
      wx.request({
        url: host + '/public',
        method: "GET",
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: (res)=> {
          let obj = res.data.data
          this.setData({
            public: obj
          });
        }

      })
    }
  },

  

})